const { MOCK } = require('../utils').settings
const axios = require('../utils/axios')
const { error } = require('../utils/error')
const {
  mockReview,
  mockReturned,
  mockContributed
} = require('./mock/contribution')
const apiError = (msg) => {
  error('50000', __filename, msg)
}
// contribution - contributed
exports.requestContributed = async (data = {}) => {
  let result = MOCK
    ? mockContributed
    : await axios.get('/user/getContributes', {
        params: data
      })
  if (!result) {
    apiError('requestContributed')
    result = mockContributed
  }
  return result
}
// contribution - returned
exports.requestReturned = async (data = {}) => {
  let result = MOCK
    ? mockReturned
    : await axios.get('/user/getReturnList', {
        params: data
      })
  if (!result) {
    apiError('requestReturned')
    result = mockReturned
  }
  return result
}
// contribution - review
exports.requestReview = async (data = {}) => {
  let result = MOCK
    ? mockReview
    : await axios.get('/user/getAuditingList', {
        params: data
      })
  if (!result) {
    apiError('requestReview')
    result = mockReview
  }
  return result
}
